import("/lay/lib/jquery-3.4.1/jquery-3.4.1.min.js")

//ajax判断教室是否存在
function exitClassRoom() {
    let classRoomName = $("#classRoomName").val();
    $.get("class-room/existClassRoom", {roomName: classRoomName}, function (result) {
        if (result.success == false) {
            $("#redmsg").remove();
            $("#message").append("<span id='redmsg' style='color: red'>" + '*教室不存在*' + "</span>");
            $("#classRoomName").val("");
        } else {
            $("#redmsg").remove();
        }
    })

}

//ajax判断班级是否存在
function exitClass() {
    let className = $("#className").val();
    $.get("_class/exitClass", {className: className}, function (result) {
        if (result.success == false) {
            $("#redmsg1").remove();
            $("#message1").append("<span id='redmsg1' style='color: red'>" + '*班级不存在*' + "</span>");
            $("#className").val("");
        } else {
            $("#redmsg1").remove();
        }
    })

}

//可能存在用户名相同的用户，（目前只是判断用户是否存在），所以修改这方面可能存在问题，到时候在这里判断（暂时埋坑）
function checkUserName() {
    let studentName = $("#studentName").val();
    $.get("student/existStudent", {studentName: studentName}, function (result) {

        if (!result) {
            $("#userMsg").remove();
            $("#stu").append("<span id='userMsg' style='color: red'>" + '*用户不存在*' + "</span>");
            $("#studentName").val("");
        } else {
            $("#userMsg").remove();
        }
    });
}
//判断实到人数，并计算出勤率
function actualNumber() {
    let factPersons = $("#factPerson").val();
    let classCount = $("#classCount").val();

    if (parseInt(factPersons) < 0||parseInt(factPersons.substring(0,1))==0) {
        $("#factPerson").val(0);
    }

    if (parseInt(factPersons) > parseInt(classCount)) {

        $("#classmsg").remove();
        $("#factPersonCount").append("<span id='classmsg' style='color: red'>" + '*实到人数不能大于应到人数*' + "</span>");
        $("#factPerson").val("");
    } else {
        $("#classmsg").remove();
        $("#work").val(parseInt((factPersons / classCount) * 100));
    }


}
//检查上台次数
function checkUpStage() {
    let upStage = $("#upStage").val();
    let factPersons = $("#factPerson").val();
    if (parseInt(upStage) < 0 || parseInt(upStage.substring(0, 1)) == 0) {
        $("#upStage").val(0);
    }
    if (parseInt(upStage) > parseInt(factPersons)) {
        $("#upStagemsg").remove();
        $("#upStages").append("<span id='upStagemsg' style='color: red'>" + '*上台次数不能大于实到人数*' + "</span>");
        $("#upStage").val(0);
    }else {
        $("#upStagemsg").remove();
    }
}
//检查警告次数
function checkWarnCount() {
    let warnCount = $("#warnCount").val();
    if (parseInt(warnCount) < 0 || parseInt(warnCount.substring(0, 1)) == 0) {
        $("#warnCount").val(0);

    }
}